home *** CD-ROM | disk | FTP | other *** search
- dBASE by the Week
- (PC Magazine Vol 6 No 2 Jan 27, 1987 Power User)
-
- Many reports need to be summarized by the WEEK OF, so a way is
- needed to convert dBASE III data fields to their preceding Sunday.
- Instead of using a complicated program, the method turns out to be:
-
- weekof=date+1-DOW(date)
-
- Editor's Note: To produce a report by WEEK OF, start with:
-
- INDEX ON date+1-DOW(date)
-
- Then modify the report .FRM file to use the same algorithm for the
- Subtotal Field. If your week starts on Sunday, just use:
-
- date+2-DOW(date)
-
- Notice, however, that the INDEX ON command will not differentiate
- between a Monday and a Friday: the algorithm converts them all to
- Sunday. If you are producing a summary report, this won't matter,
- but a detailed listing will be in WEEK OF order, with Thursdays and
- Mondays all jumbled up.
- If you need a detailed report in actual date order, you can take
- two different approaches. One way is to SORT the file on date first,
- then do the INDEX. The other approach requires a more complicated
- INDEX ON command. The index must use the WEEK OF algorithm as its
- dominant element and then differentiate between weekdays. Because the
- WEEK OF algorithm is a Date-type variable, however, you unfortunately
- can't concatenate character strings or add numerics to it, which is a
- pain in the neck.
- The INDEX ON command suggested below converts the WEEK OF Sundays
- into an integer and then adds the day-of-the-week as a trailing
- decimal:
-
- x="date+1-DOW(date)"
- INDEX ON 100*MONTH(&x)+DAY(&x)+DOW(date)/10 TO <filename>
-
- This INDEX ON formula produces indexable values in the form:
-
- Sun, 1/05/86 =105.1
- Mon, 1/06/86 =105.2
- Sun, 1/12/86 =112.1
- Mon, 1/13/86 =112.3
-
- Whether you SORT first or use this longer INDEX ON command, the
- Subtotal Formula in your .FRM file remains the same.
- If you enter "WEEK OF:" as the Subtotal Heading and use the
- following as the Subtotal Expression:
-
- CDOW(date+1-DOW(date))+', '+DTOC(date+1-DOW(date))
-
- you can create an attractive, complete Subtotal Heading that displays
- in the format: "WEEK OF: Sunday, January 6, 1986."
-